﻿namespace ClientApplication
{
    public class FirstServiceProxyPostSharp : IFirstServiceProxyPostSharp
    {
        [Sapit.PostSharp.Attributes.Cache(CacheSeconds = 10)]
        public string CallHelloWorld()
        {
            FirstService.FirstServiceSoapClient fs = new FirstService.FirstServiceSoapClient();
            string result = fs.HelloWorld();
            fs.Close();
            return result;
        }

        [Sapit.PostSharp.Attributes.CircuitBreaker(MaxConsecutiveFailures = 3, ShutOffPeriodSeconds = 20, BehaviorWhenShutOff = Sapit.Behavior.ReturnDefaultValue, ShutOffReturnValue = "The system is shut off.")]
        public string CallUnstableHelloWorld()
        {
            FirstService.FirstServiceSoapClient fs = new FirstService.FirstServiceSoapClient();
            string result = fs.UnstableHelloWorld();
            fs.Close();
            return result;
        }

        [Sapit.PostSharp.Attributes.ResponseTimeThrottle(ThrottleThresholdMilliseconds = 250, SkipCallsWhenThrottling = 3, BehaviorWhenThrottling = Sapit.Behavior.ReturnDefaultValue, ThrottleReturnValue = "The system is slow.")]
        public string CallSlowHelloWorld()
        {
            FirstService.FirstServiceSoapClient fs = new FirstService.FirstServiceSoapClient();
            string result = fs.SlowHelloWorld();
            fs.Close();
            return result;
        }

        [Sapit.PostSharp.Attributes.Timeout(TimeoutMilliseconds = 1000)]
        public string CallSlowerHelloWorld()
        {
            FirstService.FirstServiceSoapClient fs = new FirstService.FirstServiceSoapClient();
            string result = fs.SlowerHelloWorld();
            fs.Close();
            return result;
        }

        [Sapit.PostSharp.Attributes.Retry(TimesToRetry = 0)]
        public string CallFailingHelloWorld()
        {
            FirstService.FirstServiceSoapClient fs = new FirstService.FirstServiceSoapClient();
            string result = fs.FailingHelloWorld();
            fs.Close();
            return result;
        }
    }
}
